#include "connect_pool.h"
#include <mysql/mysql.h>
#include <cstring> 
#include <memory>
#include <iostream>

class MYSQLScopedConnection{
    public :
        explicit MYSQLScopedConnection(MySQLConnectionPool& pool)
        : m_pool(pool), m_conn(pool.getConnection()) { // 获取原生指针
            // std::cout << "MYSQLScopedConnection constructed, conn: " << m_conn.get() << std::endl;
        }    
        MYSQL* operator->() const {return m_conn.get();}
        MYSQL* get() const {return m_conn.get();}
        bool isValid() const {return m_conn.get()!=nullptr;}
    private:
        MySQLConnectionPool& m_pool;
        std::shared_ptr<MYSQL> m_conn;
    
};